<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>for-案例1</title>
</head>

<body>
    <script>
        // for 循环重复执行某些操作
        // 求1-100累加和
        // 1 + 2 + 3 + 4 +...+ 100 sum = sum + i
        var sum = 0; //s: 1 3
        for (var i = 1; i <= 100; i++) {
            console.log(sum += i); //i: 2 3
        }

        // 在循环外打印结果
        var sum = 0; //s: 1 3
        for (var i = 1; i <= 100; i++) {
            sum += i; //i: 2 3
        }
        console.log(sum);
    </script>
</body>

</html>